Adding file descriptor in template.
[andmenj-acm.git] / 11481 - Arrange the Numbers / 11481.cpp
blob1bcca2e78911ade1af7d29474968874249f59efe
1 /*
2 Problem: 11481 - Arrange the Numbers
3 Author: Andrés Mejía-Posada
4 (http://blogaritmo.factorcomun.org)
6 Algorithm: Inclusion-exclusion principle
8 Accepted.
9 */
11 using namespace std;
12 #include <algorithm>
13 #include <iostream>
14 #include <iterator>
15 #include <sstream>
16 #include <fstream>
17 #include <cassert>
18 #include <climits>
19 #include <cstdlib>
20 #include <cstring>
21 #include <string>
22 #include <cstdio>
23 #include <vector>
24 #include <cmath>
25 #include <queue>
26 #include <deque>
27 #include <stack>
28 #include <map>
29 #include <set>
31 const int N = 1000, mod = 1000000007;
33 long long choose[N+1][N+1], fact[N+1];
35 void prepare(){
36 /* Factorials */
37 fact[0] = fact[1] = 1;
38 for (int i=2; i<=N; ++i) fact[i] = (fact[i-1]*i)%mod;
40 /* Binomial coefficients */
41 for (int i=0; i<=N; ++i) choose[i][0] = choose[i][i] = 1;
42 for (int i=1; i<=N; ++i)
43 for (int j=1; j<i; ++j)
44 choose[i][j] = (choose[i-1][j-1] + choose[i-1][j])%mod;
47 int main(){
48 prepare();
50 int C, pizza = 1;
51 scanf("%d", &C);
52 while (C--){
53 int n, m, k;
54 scanf("%d %d %d", &n, &m, &k);
56 long long ans = 0;
57 for (int i=0; i<=m-k; ++i){
58 ans += (i & 1 ? -1 : 1) * (choose[m-k][i] * fact[n-k-i]) % mod;
59 ans %= mod;
62 ans = ((ans * choose[m][k]) % mod + mod) % mod;
64 printf("Case %d: %lld\n", pizza++, ans);
66 return 0;